using Box2DSharp.Common;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace cframework.lockstep
{
    public class LockStepBehaviour : MonoBehaviour
    {
        public int updateOrder_ls;

        protected virtual void Awake()
        {
            if (isOverride(this.Update_LS))
            {
                LockStepWorld.current.AddUpdate(Update_LS, updateOrder_ls);
            }

            if (isOverride(this.LateUpdate_LS))
            {
                LockStepWorld.current.AddLateUpdate(LateUpdate_LS, updateOrder_ls);
            }
        }

        public static bool isOverride(System.Action a)
        {
            return a.Method != a.Method.GetBaseDefinition();
        }

        protected object StartCoroutine_LS(IEnumerator e)
        {
            return LockStepWorld.current.StartCoroutine(e, this);
        }

        protected object StartTimer_LS(System.Func<bool> callback, FP delay, int repeat = -1)
        {
            return LockStepWorld.current.StartTimer(this, callback, delay, repeat);
        }

        protected virtual void Update_LS()
        {
            throw new System.Exception("The FrameSyncUpdate method has not been implemented yet.");
        }

        protected virtual void LateUpdate_LS()
        {
            throw new System.Exception("The FrameSyncLateUpdate method has not been implemented yet.");
        }
    }
}